require "extend/BaseTablePool"

local P = NewClass(BaseTablePool, ClassFromFile(...))
Vector3Ex.SetPool(P)

function P:New()
	return Vector3Ex._New()
end

function P:Recycle(v)
	if v ~= nil and (v.w ~= nil or v.Recycle == nil) then
		logError("test_recycle: "..debug.traceback())
	end


	P.super.Recycle(self, v)
end


function P:Sub(b, c)
	return b - c
end


function P:MulByQuaternionNoAlloc(vec, rot, point)
	vec:Set(point.x, point.y, point.z)
	vec:Mul(rot)
end

function P:MulByQuaternion(b, c)
	return b * c
end

function P:SubMagnitude(b, c)
	local a = self:Sub(b, c)
	local magnitude = a:Magnitude()
	self:Recycle(a)
	return magnitude
end

function P:SubMagnitudeWithoutY(b, c)
	local a = self:Sub(b, c)
	a.y = 0
	local magnitude = a:Magnitude()
	self:Recycle(a)
	return magnitude
end

function P:Copy(a, b)
	if not a or not b then
		logError("a("..tostring(a)..") or b("..tostring(b)..") is nil"..debug.traceback())
		return
	end

	a:Set(b.x, b.y, b.z)
end

function P:Lerp(a, b, t)
	return Vector3Ex.Lerp(a, b, t)
end

function P:Position(t)
	local p = self:Create()
	p:Set(t:GetPosition(nil, nil))
	return p
end

function P:SetPosition(t, pos)
	t:SetPosition(pos.x, pos.y, pos.z)
end

function P:LocalPosition(t)
	local p = self:Create()
	p:Set(t:GetLocalPosition(nil, nil))
	return p
end

function P:SetLocalPosition(t, pos)
	t:SetLocalPosition(pos.x, pos.y, pos.z)
end

function P:LocalScale(t)
	local p = self:Create()
	p:Set(t:GetLocalScale(nil, nil))
	return p
end

function P:SetLocalScale(t, pos)
	t:SetLocalScale(pos.x, pos.y, pos.z)
end

-- function P:Zero()
-- 	local a = self:Create()
-- 	a.x = 0
-- 	a.y = 0
-- 	a.z = 0
-- 	return a
-- end

-- function P:Forward()
-- 	local a = self:Create()
-- 	a.x = 0
-- 	a.y = 0
-- 	a.z = 1
-- 	return a
-- end

-- function P:Up()
-- 	local a = self:Create()
-- 	a.x = 0
-- 	a.y = 1
-- 	a.z = 0
-- 	return a
-- end


P.zero = Vector3Ex.zero
P.forward = Vector3Ex.forward
P.up = Vector3Ex.up



-- get.up 		= function() return _new(0,1,0) end
-- get.down 	= function() return _new(0,-1,0) end
-- get.right	= function() return _new(1,0,0) end
-- get.left	= function() return _new(-1,0,0) end
-- get.back	= function() return _new(0,0,-1) end
-- get.one		= function() return _new(1,1,1) end